package org.invigorare.auctions;

import static org.invigorare.auctions.data.SaleDataOpenHelper.*;
import org.invigorare.auctions.data.SaleDataOpenHelper;

import android.app.ListActivity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.SimpleCursorAdapter;

public class AuctionSaleList extends ListActivity {
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.auction_sale_list);
        
        populateList();
        
    }
    
    final static String[] colsToDisplay = new String[] {
    	SALE_TIMESTAMP,
    	TOLLRECEIPT_NO,
    	SELLER_LICENSE,
    	AGENT_LICENSE
    };

    final static int[] viewsToDisplay = new int[] {
    	R.id.saleitem_timestamp,
    	R.id.saleitem_tollReceiptNo,
    	R.id.saleitem_seller,
    	R.id.saleitem_buyer
    };
    
    private void populateList() {
    	
    	SQLiteDatabase db = SaleDataOpenHelper.getReadableDb(getApplicationContext());
    	Cursor cursor = db.query(SaleDataOpenHelper.SALE_TABLE_NAME, null, null, null, null, null, null);

    	setListAdapter(new SimpleCursorAdapter(this, R.layout.auction_sale_list_item, cursor, colsToDisplay, viewsToDisplay));
    }
    
}
